package com.waqwb.servlet;

import com.waqwb.dao.DAOFactory;
import com.waqwb.dao.UserDAO;
import com.waqwb.entity.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author JokerQ
 * @date 2020/7/15 - 14:56
 */
public class LoginServlet extends javax.servlet.http.HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String email=request.getParameter("email");
        String password=request.getParameter("password");
        UserDAO userDAO= DAOFactory.getUserDAO();
        User user= userDAO.getUser(email, password);
        System.out.println(user.toString());
        if(user!=null){
            request.getSession().setAttribute("user", user);
            response.sendRedirect("booklist");
        }else{
            response.sendRedirect("login.jsp");
        }
    }
}
